Basic Statistics


In [13]:
%matplotlib inline
from collections import Counter
import matplotlib.pyplot as plt

In [10]:
num_friends = [100,49,41,40,25,3,2,5,1,4,2,5,5,5,2,5,4,555,4,1,5,2,22]
friend_counts = Counter(num_friends)
friend_counts


Out[10]:
Counter({5: 6, 2: 4, 4: 3, 1: 2, 3: 1, 100: 1, 40: 1, 41: 1, 555: 1, 49: 1, 22: 1, 25: 1})

In [20]:
xs = range(101)
ys = [friend_counts[x] for x in xs]
plt.bar(xs, ys)
plt.axis([0, 101, 0, 25])
plt.title('Histogram of Friend Counter')
plt.xlabel('# of friends')
plt.ylabel('# of people')
plt.show()



In [21]:
num_points = len(num_friends)
largest_value = max(num_friends)
smallest_value = min(num_friends)

In [22]:
def mean(x):
    return sum(x) / len(x)

mean(num_friends)


Out[22]:
38

In [ ]: